using UnityEngine;
using System.Collections;

public class DeathCounterEmpty : State<DeathCounterControl>
{
    #region Singleton

    private static DeathCounterEmpty instance = new DeathCounterEmpty();
    public static DeathCounterEmpty Instance { get { return instance; } }
    private DeathCounterEmpty() { }

    #endregion
    
    #region State

    public override void OnEnter(DeathCounterControl behaviour)
    {

    }

    public override void OnUpdate(DeathCounterControl behaviour)
    {
        float elapsedTime = 0.0f;
        behaviour.count += Time.deltaTime * behaviour.speedEmptying;
        elapsedTime = Mathf.InverseLerp(0, behaviour.deathTimeRelativeToCutoff, behaviour.count);
        behaviour.cutoffTotal = behaviour.cutoffMin + (behaviour.cutoffDeath - behaviour.cutoffMin) * elapsedTime;

/*        behaviour.count += Time.deltaTime * behaviour.speedEmptying;
        float elapsedTime = Mathf.InverseLerp(0, behaviour.deathTime, behaviour.count);
        behaviour.cutoffTotal = behaviour.cutoffMin + elapsedTime;
*/		
        behaviour.gameObject.renderer.material.SetFloat("_Cutoff", behaviour.cutoffTotal);
    }

    public override void OnExit(DeathCounterControl behaviour)
    {

    }

    public override void OnAction(string name, DeathCounterControl behaviour, object value)
    {

    }

    #endregion
}
